<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>


<style type="text/css">
/* 动态的css */
.dynamics{
border-bottom:1px solid #d0d0d0;
}

.dynamics-head{
float:left;width:10%;height:100%
}


.dynamics-head-img{
padding-top:30%;height:90%;width:90%;
}

.dynamics-username{
float:left;width:90%;height:100%;
}

.dynamics-content{
border-bottom:1px solid #d0d0d0;
}

</style>
<script >
$(function(){
	var currentgroupid="${currentGroup.groupid}";

	 
	$.post("groupgetAllShares.do",
			{
				groupid:currentgroupid
			},function(data){
				html="";
				for (var i = 0; i < data.length; i++){
					html+="<div class='dynamics'><div class='dynamics-head'><img class='dynamics-head-img' src='"+
					data[i].head+"'></div><div class='dynamics-username'><h1 class='dynamics-content'>"+data[i].username+
					"</h1><p>"+data[i].content+"</div>&nbsp;</div>"
				}
				$("#groupshares").empty();
				$("#groupshares").append(html);
			},"json" 
	);  
	
//}
//-------------------初始加载事件↑--------------------------表单↓---------------------------------------------------
//提交分享的按钮事件
$("#sharesubmit").click(function(){
	var param="groupsharecontent="+$('#sharecontent').val()+"&groupid="+currentgroupid;
$.ajax({
	type : 'post',
	url : 'groupusershare.do',
	data : param,
	success : function(data) {
		alert("发布分享成功！");
		$.post("groupgetAllShares.do",
				{
					groupid:currentgroupid
				},function(data){
					html="";
					for (var i = 0; i < data.length; i++){
						html+="<div class='dynamics'><div class='dynamics-head'><img class='dynamics-head-img' src='"+
						data[i].head+"'></div><div class='dynamics-username'><h1 class='dynamics-content'>"+data[i].username+
						"</h1><p>"+data[i].content+"</div>&nbsp;</div>"
					}
					$("#groupshares").empty();
					$("#groupshares").append(html);
				},"json" 
		);
	},
	error : function() {
		alert("出错了！");
	}
}); 
});

//载入负责人的按钮事件
$("#choseleader").click(function(){
	$.post("groupgetallusers.do",
			{
				groupid:currentgroupid
			},function(data){
				html="";
				for (var i = 0; i < data.length; i++){
					html+="<input name='leader' type='radio' value="+data[i].userid+" checked='checked' />"+data[i].username
				}
				$("#choseleaderdiv").empty();
				$("#choseleaderdiv").append(html);
			},"json" 
		);
});

//载入任务参与者的按钮事件
$("#chosemember").click(function(){
	$.post("groupgetallusers.do",
			{
		groupid:currentgroupid
			},function(data){
				html="";
				for (var i = 0; i < data.length; i++){
					html+="<input name='member' type='checkbox' value="+data[i].userid+" />"+data[i].username
				}
				$("#chosememberdiv").empty();
				$("#chosememberdiv").append(html);
			},"json" 
		);
});

//提交任务的按钮事件
$("#missionsubmit").click(function(){
		  var param="missionname="+$('#missionname').val()+"&groupid="+currentgroupid+"&missiondescription="+$('#missiondescription').val()+"&leaderid=";
		  param+=$("#choseleaderdiv input:radio[name='leader']:checked").val();
		  param+="&memberid=";
		  $("#chosememberdiv input:checkbox[name='member']:checked").each(function(){
		   param+=$(this).val()+",";
		  });
		  param+="&starttime="+$("input[name='missionstarttime']").val();
		  param+="&endtime="+$("input[name='missionendtime']").val(); 
	$.ajax({
		type : 'post',
		url : 'groupaddmission.do',
		data : param,
		success : function(data) {
			alert("发布任务成功！");
			$.post("groupgetAllShares.do",
					{
						groupid:currentgroupid
					},function(data){
						html="";
						for (var i = 0; i < data.length; i++){
							html+="<div class='dynamics'><div class='dynamics-head'><img class='dynamics-head-img' src='"+
							data[i].head+"'></div><div class='dynamics-username'><h1 class='dynamics-content'>"+data[i].username+
							"</h1><p>"+data[i].content+"</div>&nbsp;</div>"
						}
						$("#groupshares").empty();
						$("#groupshares").append(html);
					},"json" 
			);
		},
		error : function() {
			alert("出错了！");
		}
	}); 
});

//---------------任务↑---------------------------活动↓-------------------------------------	

//载入活动参与者的按钮事件
$("#choseactivitymember").click(function(){

	$.post("groupgetallusers.do",
			{
				groupid:currentgroupid
			},function(data){
				html="";
				for (var i = 0; i < data.length; i++){
					html+="<input name='activitymember' type='checkbox' value="+data[i].userid+" />"+data[i].username
				}
				$("#choseactivitymemberdiv").empty();
				$("#choseactivitymemberdiv").append(html);
			},"json" 
		);
});

//提交活动的按钮事件
$("#activitysubmit").click(function(){
		  var param="activityname="+$('#activityname').val()+"&groupid="+currentgroupid+"&activitydescription="+$('#activitydescription').val();
		  param+="&activityaddress="+$('#activityaddress').val();
		  param+="&activitymemberid=";
		  $("#choseactivitymemberdiv input:checkbox[name='activitymember']:checked").each(function(){
		   param+=$(this).val()+",";
		  });
		  param+="&starttime="+$("input[name='activitystarttime']").val();
		  param+="&endtime="+$("input[name='activityendtime']").val(); 
		  alert(param);
	$.ajax({
		type : 'post',
		url : 'groupaddactivity.do',
		data : param,
		success : function(data) {
			alert("发布活动成功！");
			$.post("groupgetAllShares.do",
					{
						groupid:currentgroupid
					},function(data){
						html="";
						for (var i = 0; i < data.length; i++){
							html+="<div class='dynamics'><div class='dynamics-head'><img class='dynamics-head-img' src='"+
							data[i].head+"'></div><div class='dynamics-username'><h1 class='dynamics-content'>"+data[i].username+
							"</h1><p>"+data[i].content+"</div>&nbsp;</div>"
						}
						$("#groupshares").empty();
						$("#groupshares").append(html);
					},"json" 
			);
		},
		error : function() {
			alert("出错了！");
		}
	}); 
});


//查询出没有加入项目的同事
$("#invite").click(function(){
	$.post("intviteworkernotingroup.do",
			{
				groupid:currentgroupid
			},function(data){
				html="";
				for (var i = 0; i < data.length; i++){
					html+="<input name='invitedworker' type='checkbox' value="+data[i].userid+" />"+data[i].username
				}
				$("#inviteworkers").empty();
				$("#inviteworkers").append(html);
				$("#invitetoggle").toggle(1000);
			},"json" 
		);
});

//邀请同事
$("#invitesubmit").click(function(){
	 var param="groupid="+currentgroupid;
	  param+="&groupinvitedmemberid=";
	  $("#inviteworkers input:checkbox[name='invitedworker']:checked").each(function(){
	   param+=$(this).val()+",";
	  });
	  alert(param);
$.ajax({
	type : 'post',
	url : 'invitegroupworker.do',
	data : param,
	success : function(data) {
		alert("已邀请加入！");
		$("#invitetoggle").hide(1000);
	},
	error : function() {
		alert("出错了！");
	}
 }); 
});

//----------------------发布表单↑----------------------动态↓-------------------------------------------------

});

</script>
</head>
<body>
					<div  style="border-bottom:1px solid #d0d0d0;border-radius:5px">
						<h1>${currentGroup.groupname}</h1>
						
						<h3>${currentGroup.description}</h3>
						<button id="invite" class="btn btn-warning" type="button">邀请同事加入</button>
						<div id="invitetoggle" style="display:none;">
						<div id="inviteworkers"></div>
						<button id="invitesubmit" class="btn " type="button">邀请</button>
						</div>						
					</div>
					
					
					<div class="tabbable" id="tabs-666534">
						<ul class="nav nav-tabs">
							<li class="active"><a href="#panel-share" data-toggle="tab">发分享</a></li>
							<li><a href="#panel-mission" data-toggle="tab">发任务</a></li>
							<li><a href="#panel-activity" data-toggle="tab">发活动</a></li>
						</ul>
						<div class="tab-content">
						
							<!-- 发起分享的表单 -->
							<div class="tab-pane active" id="panel-share">
								<form id="shareform" method="get" role="form">
									<div class="form-group">
										<textarea
										placeholder="请输入分享内容" rows="3" class="form-control" name="content" id="sharecontent" ></textarea>
									</div>
									<button style="float:right" id="sharesubmit" type="button" class="btn btn-default">分享</button>
								</form>
							</div>
							
							<!-- 发起任务的表单 -->
							<div class="tab-pane" id="panel-mission">
								
									<div class="form-group">
										<input
										placeholder="请输入任务名称"	type="text" class="form-control" id="missionname" />
									</div>
									<div class="form-group">
										<button class="btn" id="choseleader" type="button">选择负责人</button>
										<div id="choseleaderdiv"></div>
									</div>
									<div class="form-group">
										<a style="float:left">开始时间</a>
										<div style="float:left" class="input-append date teamtimepicker" id="datetimepicker" data-date="2017-08-04 01:00:00" data-date-format="yyyy-mm-dd hh:ii:ss">
    										<input name="missionstarttime" size="16" type="text" value="2017-08-04 01:00:00" >
    										<span class="add-on"><i class="icon-th"></i></span>
										</div> 
										<a style="float:left">结束时间</a>
										<div style="float:left" class="input-append date teamtimepicker"  data-date="2017-08-04 01:00:00" data-date-format="yyyy-mm-dd hh:ii:ss">
    										<input name="missionendtime" size="16" type="text" value="2017-08-04 01:00:00" >
    										<span class="add-on"><i class="icon-th"></i></span>
										</div> 
									</div>
									<br />
									<br />
									<div class="form-group">
										<button class="btn" id="chosemember" type="button">选择参与者</button>
										<div id="chosememberdiv"></div>
									</div>
									<div class="form-group">
											<textarea
											placeholder="请输入任务描述" rows="3" class="form-control" name="content" id="missiondescription" ></textarea>
									</div>
									  
									<button style="float:right" id="missionsubmit" type="submit" class="btn btn-default">发布</button>
							</div>
							
<!------------------------------------------ 发起活动的表单--------------------------------------------------------->
							<div class="tab-pane" id="panel-activity">
								<div class="form-group">
										<input
										placeholder="请输入活动名称"	type="text" class="form-control" id="activityname" />
									</div>
									<div class="form-group">
										<button class="btn" id="choseactivitymember" type="button">选择参与者</button>
										<div id="choseactivitymemberdiv"></div>
									</div>
									<div class="form-group">
										<a style="float:left">开始时间</a>
										<div style="float:left" class="input-append date teamtimepicker" id="datetimepicker" data-date="2017-08-04 01:00:00" data-date-format="yyyy-mm-dd hh:ii:ss">
    										<input name="activitystarttime" size="16" type="text" value="2017-08-04 01:00:00" >
    										<span class="add-on"><i class="icon-th"></i></span>
										</div> 
										<a style="float:left">结束时间</a>
										<div style="float:left" class="input-append date teamtimepicker"  data-date="2017-08-04 01:00:00" data-date-format="yyyy-mm-dd hh:ii:ss">
    										<input name="activityendtime" size="16" type="text" value="2017-08-04 01:00:00" >
    										<span class="add-on"><i class="icon-th"></i></span>
										</div> 
									</div>
									<div class="form-group">
										<input placeholder="请输入活动地点" type="text"
											class="form-control"
											id="activityaddress" />
									</div>
									<div class="form-group">
											<textarea
											placeholder="请输入活动描述" rows="3" class="form-control" name="content" id="activitydescription" ></textarea>
									</div>					  
									<button style="float:right" id="activitysubmit" type="submit" class="btn btn-default">发布</button>
							</div>
						</div>
					</div>
				<h3>小组动态</h3>	
				<div id="groupshares">
				
				</div>
									
									
				
</body>
</html>